package cn.ggb.eduorder.service.impl;

import cn.ggb.commonutils.OrderVo.EduCourseVo;
import cn.ggb.commonutils.OrderVo.UcenterMemberVo;
import cn.ggb.eduorder.client.eduClient;
import cn.ggb.eduorder.client.ucenterClient;
import cn.ggb.eduorder.entity.TOrder;
import cn.ggb.eduorder.mapper.TOrderMapper;
import cn.ggb.eduorder.service.TOrderService;
import cn.ggb.eduorder.utils.OrderNoUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-04-15
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {

    @Autowired
    private eduClient eduClient;
    @Autowired
    private ucenterClient ucenterClient;

    @Override
    public String createOrders(String courseId, String userId) {

        //根据用户id获取用户信息
        UcenterMemberVo userInfo = ucenterClient.getUserInfo(userId);

        //根据课程id获取课程信息
        EduCourseVo courseInfoVo = eduClient.getCourseInfoVo(courseId);

        //创建订单
        TOrder order = new TOrder();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfoVo.getTitle());
        order.setCourseCover(courseInfoVo.getCover());
        order.setTeacherName("test");
        order.setTotalFee(courseInfoVo.getPrice());
        order.setMemberId(userId);
        order.setMobile(userInfo.getMobile());
        order.setNickname(userInfo.getNickname());
        order.setStatus(0);
        order.setPayType(1);
        baseMapper.insert(order);

        return order.getOrderNo();
    }
}
